#ifndef MACROS_H_
#define MACROS_H_
/*******************************************************************************
 * File name: 		macros.h
 * Description: 
 * Project: 		_framework
 * Target: 			LPC1788
 * Compiler: 		arm-none-eabi-gcc
 * Date: 			09-07-2012
 * Author: 			Kuba
 * Based on: 		---
 ******************************************************************************/

/*==============================================================================
 Includes
==============================================================================*/

/*==============================================================================
 Defines
==============================================================================*/
/*------------------------------------------------------------------------------
 macro name:		SET_BIT
 description:		set bit at a position
 parameters:		position
 returned value:	-
------------------------------------------------------------------------------*/
# define SET_BIT(pos) 				(1 << (pos))

/*------------------------------------------------------------------------------
 macro name:		SET_BITS
 description:		set bit field at a position
 parameters:		value, position
 returned value:	-
------------------------------------------------------------------------------*/
# define SET_BITS(val, pos) 	((val) << (pos))

/*------------------------------------------------------------------------------
 macro name:		CHECK_BIT
 description:		check if bit is set in a value
 parameters:		variable, position
 returned value:	-
------------------------------------------------------------------------------*/
# define CHECK_BIT(val, pos)		((val) & (1<<(pos)))

/*------------------------------------------------------------------------------
 macro name:		BIT_POS
 description:		check at what position bit is set
 parameters:		variable, position
 returned value:	-
------------------------------------------------------------------------------*/
# define BIT_POS(val) \
	(((val) & 0x1)? 		0 	: 	\
	((val) & 0x2)? 			1 	:  	\
	((val) & 0x4)? 			2 	: 	\
	((val) & 0x8)? 			3 	: 	\
	((val) & 0x10)? 		4 	: 	\
	((val) & 0x20)? 		5 	: 	\
	((val) & 0x40)? 		6 	: 	\
	((val) & 0x80)? 		7 	: 	\
	((val) & 0x100)? 		8 	: 	\
	((val) & 0x200)? 		9 	: 	\
	((val) & 0x400)? 		10 	: 	\
	((val) & 0x800)? 		11 	: 	\
	((val) & 0x1000)? 		12 	: 	\
	((val) & 0x2000)? 		13 	: 	\
	((val) & 0x4000)? 		14 	: 	\
	((val) & 0x8000)? 		15 	: 	\
	((val) & 0x10000)? 		16 	: 	\
	((val) & 0x20000)? 		17 	: 	\
	((val) & 0x40000)? 		18 	: 	\
	((val) & 0x80000)? 		19 	: 	\
	((val) & 0x100000)? 	20 	: 	\
	((val) & 0x200000)? 	21 	: 	\
	((val) & 0x400000)? 	22 	: 	\
	((val) & 0x800000)? 	23 	: 	\
	((val) & 0x1000000)?	24 	: 	\
	((val) & 0x2000000)?	25 	: 	\
	((val) & 0x4000000)?	26 	: 	\
	((val) & 0x8000000)?	27 	: 	\
	((val) & 0x10000000)?	28 	: 	\
	((val) & 0x20000000)?	29 	: 	\
	((val) & 0x40000000)?	30 	: 	\
	((val) & 0x80000000)?	31 	: 	-1)

/*------------------------------------------------------------------------------
 macro name:		IS_POWER2
 description:		check if val is power of 2
 parameters:		value to check
 returned value:	-
------------------------------------------------------------------------------*/
# define IS_POWER2(val)		(!((val)&((val) - 1)))

/******************************************************************************
* END OF FILE
******************************************************************************/





#endif /* MACROS_H_ */
